package cn.dnui_xqh414.dnuifood_16110100414;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import cn.dnui_xqh414.dnuifood_16110100414.bean.getAllCommentsBean;
import cn.dnui_xqh414.dnuifood_16110100414.fragment_adapter_and_vhoder.RecycleItemTouchHelper;
import cn.dnui_xqh414.dnuifood_16110100414.fragment_adapter_and_vhoder.Rv_Adapter_orderList;
import cn.dnui_xqh414.dnuifood_16110100414.listener.OnRetrofitListener;
import cn.dnui_xqh414.dnuifood_16110100414.model.UserModel;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.MenuItem;

import java.util.List;

public class MyOrderActivity extends BaseActivity implements OnRetrofitListener {

    private RecyclerView recyclerView;
    private List<getAllCommentsBean> list;
    private Rv_Adapter_orderList adapter_orderList;

    private Toolbar toolbar;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }
    @Override
    void initViews() {
        setContentView(R.layout.activity_my_order);
        toolbar = findViewById(R.id.toolbar_AllOrder);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle("我的订单");
        recyclerView = findViewById(R.id.rv_order);

        RecyclerView.LayoutManager manager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(manager);
        recyclerView.setHasFixedSize(true);

        adapter_orderList = new Rv_Adapter_orderList(this);
        UserModel model = new UserModel();
        SharedPreferences sharedPreferences = getSharedPreferences("userinfo",MODE_PRIVATE);
        int userId = sharedPreferences.getInt("userid",-1);
        model.getAllOrder(userId,this);
        recyclerView.setAdapter(adapter_orderList);
        ItemTouchHelper.Callback callback = new RecycleItemTouchHelper(adapter_orderList);
        ItemTouchHelper helper = new ItemTouchHelper(callback);
        helper.attachToRecyclerView(recyclerView);
    }

    @Override
    void initEvents() {

    }

    @Override
    void initData() {

    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        super.onOptionsItemSelected(item);
        switch (item.getItemId())
        {
            case android.R.id.home:
                finish();
                break;
                }
                return true;
    }

    @Override
    public void onSuccess(Object object, int flag) {
        list = (List<getAllCommentsBean>) object;
        adapter_orderList.setList(list);
    }

    @Override
    public void onFailure(String msg) {

    }
}
